<?php
namespace Pub\tool;
defined('IN_IA') or exit('Access Denied');
use Pub\cache\Cache;

class Setting
{
    const ADD = 'give';  //签到新增范围（数组）
    const SUB = 'sub'; //每日漏签扣除积分范围（数组）
    const CURRENCY_NAME = "currency_name";  //奖品、金币名称
    const WEB_NAME = "web_name";  //网站名称
    const WEB_ICON = "web_icon"; //  网站图标
    const WEB_DESCRIPTION = "web_description";  //网站描述
    const SHOW_HELP = "show_help";  //是否显示帮助信息
    const HELP = "help";  //赚取积分提示
    const USE_BALANCE = "use_balance";
    const SIGN_KEYWORD = "sign_keyword";  //签到触发关键字
    const TICKET = "ticket";  //兑换签到二维码ticket
    const TICKET_EXPIRE = "ticket_expire";  //兑换签到二维码ticket过期时间
    const SCENE_ID = "scene_id";  //签到二维码的scene_id

    /**
     * 获取参数
     * @param string $_filed 参数名
     * @return string 参数值
     */
    public static function get($_filed)
    {
        global $_W;
        $_uniacid = $_W["account"]["uniacid"];
        $_data = Cache::get(Cache::SETTING.$_filed,array('uniacid'=>$_uniacid));
        if($_data && !KUYUAN_DEBUG){
            return $_data;
        }else{
            $_data = pdo_get('kuyuan_fm_setting',array('uniacid'=>$_uniacid),array($_filed));
            if($_data) Cache::set(Cache::SETTING.$_filed,$_data[$_filed],array('uniacid'=>$_uniacid));
            return ''.$_data[$_filed];
        }
    }

    /**
     * 清空参数
     */
    public static function clear()
    {
        global $_W;
        $_uniacid = $_W["account"]["uniacid"];
        $Class = new \ReflectionClass('Pub\tool\Setting');
        $_constants = $Class->getConstants();
        foreach($_constants as $_v){
            Cache::remove(Cache::SETTING.$_v,array('uniacid'=>$_uniacid));
        }
    }

}
